home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- //
- // SimplePrint
- //
- // SimplePrint makes the minimum calls required to print one page under the
- // "new" Print Manager. It will print 85 rectangles that are scaled,
- // rotated, and framed. The gxColor of the rectangle frmae will be a color derived
- // from the HSV color space. Each rectangle will contain a slightly different
- // HSV color.
- //
- // By the way, if an error occurs, you will end up in Macsbug with an
- // appropriate error message.
- //
- //
- // History:
- // 6/91 - New
- // 8/93 - convert files to work with the ß2 "GXified" interface files
- //
- // ©1991 - 1993 Apple Computer, Inc. All rights reserved.
- //
- //---------------------------------------------------------------------------
-
-
- #include <Types.h> // defines noErr
- #include <Errors.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Dialogs.h>
- #include <Memory.h>
-
- #include <Collections.h>
- #include <PrintingManager.h>
- #include <graphics routines.h>
- #include <graphics libraries.h>
- #include <math routines.h>
-
- #define f(a,b) (((fixed) (a) << 16) + (b))
-
- #define kDebugging false // Set to TRUE, for error & notice posting.
-
-
- void PrintOne(gxShape thePage);
- void DrawPage(gxShape thePage);
-
-
- //------ PrintOne ---------------------------------------------------------
- //
- // Print the contents of "thePage". This function contains the minimum
- // number of calls required to print a page under the "new" Print Manager.
- //
- void PrintOne(gxShape thePage)
- {
- OSErr anErr;
- gxJob theJob;
-
- // We allocate space for a new job which contains a default format and
- // paper type.
- anErr = GXNewJob(&theJob);
-
- if (anErr != noErr) DebugStr("\p Blam! GXNewJob");
-
- // Display the extensible Print dialog box
- if (GXJobPrintDialog(theJob, nil) == gxOKSelected)
- {
- // Start sending the job to a spool file. The job will be
- // named: "Spinning Rectangles Document", and it contains 1 page
- // The name will be displayed in he status dialogs.
- GXStartJob(theJob, "\pSpinning Rectangles Document", 1);
-
- if (GXGetJobError(theJob) != noErr) DebugStr("\p Blam! GXStartJob");
-
- // Send the entire page down to the printer. We can send the entire
- // job because all of the shapes that are being printed have been
- // collected into "thePage", therefore the Print Manager does not
- // need to do any work.
- GXPrintPage(theJob, 1, GXGetJobFormat(theJob, 1), thePage);
- if (GXGetJobError(theJob) != noErr) DebugStr("\p Blam! GXPrintPage");
-
- // This calls tells the Pritn Manager that we have finished sending the spool
- // file, therefore terminate the transmission (i.e. the connection to the
- // printer.
- GXFinishJob(theJob);
- if (GXGetJobError(theJob) != noErr) DebugStr("\p Blam! GXFinishJob");
- }
-
- anErr = GXDisposeJob(theJob);
-
- if (anErr != noErr) DebugStr("\p Blam! GXDisposeJob");
- }
-
-
-
- //------ DrawPage ---------------------------------------------------------
- //
- // In this function, we collect the 85 rectangles that are scaled, rotated, and
- // framed into the gxShape called "thePage". Each gxRectangle will be drawn with a
- // different HSV gxColor. All of the rectangles will be collected into "thePage",
- // which will be printed via the PrintOne function.
- //
- void DrawPage(gxShape thePage)
- {
- gxShape myRect;
- gxRectangle rectangleBounds, myRectDimensions = {ff(0), ff(0), ff(300), ff(300)};
- short drawLoop;
- gxColor frameColor;
- fixed x, y;
-
- // Create the gxRectangle to be drawn.
- myRect = GXNewRectangle(&myRectDimensions);
-
- // Set up the HSV gxColor space, which will allow us to change the gxColor
- // of the framed gxRectangle. As we scale and rotate it 85 times.
- frameColor.space = gxHSVSpace;
- frameColor.profile = nil;
- frameColor.element.hsv.hue = 0x0000;
- frameColor.element.hsv.saturation = 0xFFFF;
- frameColor.element.hsv.value = 0x7FFF;
-
-
- // Set up the various components of the gxRectangle.
- GXSetShapeFill (myRect, gxClosedFrameFill);
- GXSetShapePen(myRect, 0);
- GXSetShapeColor(myRect, &frameColor);
-
-
- // Move the gxRectangle to the center of the page, that will eventually be printed
- GXMoveShapeTo (myRect, ff(150), ff(150));
-
-
- // Add the 85 rectangles to "thePage". Each gxRectangle will be scaled, rotated,
- // and framed in an HSV gxColor.
-
- for (drawLoop = 0; drawLoop < 85; drawLoop++)
- {
- gxShape tempShape;
-
- // The first time through the loop, we add an unrotated gxRectangle to the
- // "thePage".
- AddToShape(thePage, myRect);
-
- // Make a temporary copy of the gxRectangle to "tempShape". If we did not make
- // a copy of "myRect", we would add the same gxShape to the picture over and over.
- // The graphics system assumes that the gxShape has not changed, unless the
- // tranform of the gxShape or the gxShape was re-created, since the last time the
- // gxShape was drawn or added to the picture.
- tempShape = GXCopyToShape (nil, myRect);
-
- // We decrement the owner count to 1, by calling GXDisposeShape, so that "thePage"
- // is the only owner. Whcih enables the graphics system to realize that the
- // gxShape has changed since, the last time it had been drawn.
- GXDisposeShape (myRect);
-
- // Re-create the gxShape
- myRect = tempShape;
-
- // Get the bounds of the gxRectangle.
- GXGetShapeBounds(myRect, 0L, &rectangleBounds);
-
- // Divide the hieght and width of the gxRectangle bounds by 2
- x = rectangleBounds.left + rectangleBounds.right >> 1;
- y = rectangleBounds.top + rectangleBounds.bottom >> 1;
-
- // Scale and rotate the gxRectangle.
- GXScaleShape(myRect, f(0, 0xF800), f(0, 0xF800), x, y);
- GXRotateShape(myRect, ff(25), x, y);
-
- // Change the gxColor of the gxRectangle frame, and set the new gxColor to the gxRectangle.
- frameColor.element.hsv.hue += 0x0300;
- GXSetShapeColor(myRect, &frameColor);
- }
-
- GXDisposeShape (myRect);
- }
-
-
-
- //------ main -------------------------------------------------------------
-
- main()
- {
- OSErr anErr;
-
- MaxApplZone(); MoreMasters(); MoreMasters();
-
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitDialogs(nil);
- InitCursor();
-
- if (kDebugging) {
- SetGraphicsLibraryErrors();
- SetGraphicsLibraryNotices();
- }
-
- // Standard initilization to get the graphics system set up. We also gxInitialize
- // the error and notice functions of the system to allow us to be alerted when
- // an error occurs or when we do something that does not make sense to the
- // graphics system.
- GXEnterGraphics();
-
-
- // Initialize the "new" Print Manager
- anErr = GXInitPrinting();
- if (anErr != noErr) DebugStr("\p Blam! GXInitPrinting");
- {
- gxShape thePage;
-
- // Create "thePage" gxShape, and fill it full of rectangles by calling DrawPage ()
- thePage = GXNewShape(gxPictureType);
- DrawPage(thePage);
-
- // Print "thePage" and dispose of it.
- PrintOne(thePage);
- GXDisposeShape(thePage);
- }
-
- // Close up the "new" Print Manager
- anErr = GXExitPrinting();
- if (anErr != noErr) DebugStr("\p Blam! GXExitPrinting");
-
- // Close up the graphics system
- GXExitGraphics();
- }